#include "DesktopHelper.h"

RECT rtIconArr[2][10] = {50, 130, 160, 250,
					160, 130, 270, 250,
					270, 130, 380, 250,
					380, 130, 490, 250,
					540, 130, 760, 250,
					50, 250, 160, 370,
					160, 250, 270, 370,
					270, 250, 490, 370,
					540, 250, 650, 370,
					650, 250, 760, 370,

					50, 130, 270, 250,
					270, 130, 380, 250,
					380, 130, 490, 250,
					540, 130, 650, 250,
					650, 130, 760, 250,
					50, 250, 160, 370,
					160, 250, 270, 370,
					270, 250, 380, 370,
					380, 250, 490, 370,
					540, 250, 760, 370,
};
void GetOriginalRect(RECT &rc, int nPos)
{
	
	int nRow;
	int nCol;


	nRow = nPos / MAX_ICONS_OF_ROW;
	nCol = nPos % MAX_ICONS_OF_ROW;

//jdhuang 20130924
#if 0
	rc.left = nCol*AVG_ICON_WIDTH;
	rc.top = nRow*AVG_ICON_HEIGHT;

	rc.right = (nCol+1)*AVG_ICON_WIDTH;
	rc.bottom = (nRow+1)*AVG_ICON_HEIGHT;
#else
	rc.left = rtIconArr[0][nPos].left;
	rc.right = rtIconArr[0][nPos].right;
	rc.top = rtIconArr[0][nPos].top;
	rc.bottom = rtIconArr[0][nPos].bottom;
#endif
}

void ClipRectForIcon(RECT &newRc, RECT &origRc)
{
//jdhuang 20130924
#if 0
	newRc.left = origRc.left + (AVG_ICON_WIDTH-AC_ICON_WIDTH)/2;
	newRc.top = origRc.top + (AVG_ICON_HEIGHT-AC_ICON_HEIGHT-AC_TEXT_HEIGHT)/2;

	newRc.right = origRc.right - (AVG_ICON_WIDTH - AC_ICON_WIDTH)/2;
	newRc.bottom = origRc.bottom -(AVG_ICON_HEIGHT - AC_ICON_HEIGHT - AC_TEXT_HEIGHT)/2 - AC_TEXT_HEIGHT;
#else
	newRc.left = origRc.left;
	newRc.top = origRc.top;

	newRc.right = origRc.right - AC_GAP_ICON;
	newRc.bottom = origRc.bottom - AC_GAP_ICON;
#endif
}

//jdhuang 20100121
void ClipRectForText(RECT &newRc, RECT &origRc)
{
	newRc.left = origRc.left + (AVG_ICON_WIDTH-AC_ICON_WIDTH)/2 - 5;
	newRc.top = origRc.top + (AVG_ICON_HEIGHT-AC_ICON_HEIGHT-AC_TEXT_HEIGHT)/2 + AC_ICON_HEIGHT;

	newRc.right = origRc.right - (AVG_ICON_WIDTH - AC_ICON_WIDTH)/2 + 5;
	newRc.bottom = origRc.bottom -(AVG_ICON_HEIGHT - AC_ICON_HEIGHT - AC_TEXT_HEIGHT)/2;
}


BOOL GetFocusRect(RECT &rc, int nIndex)
{
	RECT origRc;
	GetOriginalRect(origRc, nIndex);

	ClipRectForIcon(rc, origRc);

	return TRUE;
}

DWORD GetPositionFromPoint(int xPos, int yPos)
{
	int nRol = xPos / AVG_ICON_WIDTH;
	int nRow = yPos / AVG_ICON_HEIGHT;

#ifdef __ALIGN_ICON_MODE_COL__
	return (DWORD)(nRow + nRol*MAX_ICONS_OF_COL);
#else
	return (DWORD)(nRow*MAX_ICONS_OF_ROW + nRol);
#endif
}
